import 'package:get/get.dart';
import 'package:meiyunapp/entity/home_top_data_entity.dart';
import 'package:meiyunapp/entity/near_bystore_entity.dart';
import 'package:meiyunapp/net/api_service.dart';
import 'package:meiyunapp/net/base/error_entity.dart';

class HomeCollection extends SuperController<List<NearBystoreList>> {

  HomeTopDataEntity? homeData;

  void getBottomData() {
    ApiService.instance.request<NearBystoreEntity>(
      "home/data/stores",
      params: {
        "cityName": "上海市",
        "latitude": 31.158766,
        "longitude": 121.359281
      },
      success: (NearBystoreEntity data) {
        change(data.xList, status: RxStatus.success());
      },
      error: (ErrorEntity entity) {
        change(null, status: RxStatus.error(entity.message));
      },
    );
  }

  void getHomeTopData() {
    ApiService.instance.request<HomeTopDataEntity>(
      "home/data/tdata",
      params: {"cityId": 310100, "cityName": "上海"},
      success: (HomeTopDataEntity data) {
        updateData(data);
      },
      error: (ErrorEntity entity) {

      },
    );
  }

  void updateData(HomeTopDataEntity data) {
    homeData = data;
    update();
  }


  @override
  void onReady() {
    getHomeTopData();
    getBottomData();
    super.onReady();
  }

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onDetached() {}

  @override
  void onInactive() {}

  @override
  void onPaused() {}

  @override
  void onResumed() {}
}
